﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using System.Text;

using Gift.Model;

namespace WebSite.cn
{
    public partial class head : System.Web.UI.UserControl
    {

  readonly BasePage theBase = new BasePage();

    public string lan = "";
    public string logo = "";
    public string shop = "0";
    public string shopname = "";
    public string shopurl = "";
    public StringBuilder sbTopic = new StringBuilder();
    public string totalprice = "0";
    public string typemsg = "";

    string _displayTop = "";

    public string DisplayTop
    {
        get {
            if (!Request.Path.Contains("index.aspx"))
            {
                _displayTop = "display:none;";
            }
            return _displayTop; }
      
    }

    StringBuilder _sbCarInfo = new StringBuilder();

    public StringBuilder SbCarInfo
    {
        get { return _sbCarInfo; }
    }



    public StringBuilder sbHeadMenu = new StringBuilder();

    public string MemberInfo
    {
        get {
            if (theBase.LoginUserMember != null)
            {
                if (theBase.LoginUserMember.DicUserCardList != null && theBase.LoginUserMember.DicUserCardList.Count > 0)
                {
                    StringBuilder sbInfo = new StringBuilder("您的卡券详情 ");
                    foreach (dbCard card in theBase.LoginUserMember.DicUserCardList.Values)
                    {

                        sbInfo.AppendFormat(" *卡号:{0},卡名称:{1},卡面值:{2},<a href='/cn/exitCard.aspx?cid={3}'>[删除] &nbsp;</a>"
                                              , card.cardcode
                                              , card.CardTypeName
                                              , card.cardprice.ToString("#,##")
                                              , card.cardid);
                    }
                    return sbInfo.ToString();
                }
                
            }
            return string.Empty;    
        }    
    }


    public BasePage TheBasePage
    {
        get
        {
            return new BasePage();
        }
    }

    // Methods
    private void Bind()
    {
        if (sbHeadMenu.Length > 0)
        {
            return;
        }
       // this.txtKeyName.Value = "";// Request.QueryString["key"];
        this.logo = "<img src='../uploadfile/banner/" + info.info1("", "shoplogo") + "' />";
        this.shopname = info.info1("", "shopname");
        this.shopurl = info.info1("", "shopurl");
        string sql = "select classid,classlink,classname from DB_Class where parentid=0 and visible=1 and classname<>'' and (classpcs='顶部' or classpcs='顶部和底部')  order by classorder";
        DataTable table = SQLAccess.GreatDs(sql).Tables[0];
        if (table.Rows.Count > 0)
        {
            string sClass = string.Empty;
            foreach (DataRow row in table.Rows)
            {
                
                if (row["classlink"].ToString() != "")
                {
                    sClass = string.Empty;
                    if (base.Request.Url.ToString().ToLower().IndexOf(row["classlink"].ToString().ToLower()).ToString() != "-1")
                    {
                        sClass = " class='current' ";
                    }


                    sbHeadMenu.AppendFormat("<li><a href=\"/cn/{0}\" {2}>{1}</a></li>"
                                                , row["classlink"]
                                                , row["classname"]
                                                , sClass
                                                );
                    continue;
                }
                if (base.Request.QueryString["cid"] != null)
                {
                    sClass = string.Empty;
                    if (base.Request.QueryString["cid"].ToString() == row["classid"].ToString())
                    {
                        sClass = " class='current' ";
                    }
                        sbHeadMenu.AppendFormat("<li><a href=\"/cn/{0}\" {2}>{1}</a></li>"
                                           , "content.aspx?cid=" + row["classid"]
                                           , row["classname"]
                                           , sClass
                                           );


                    continue;
                }
                sbHeadMenu.AppendFormat("<li><a href=\"/cn/{0}\">{1}</a></li>"
                                          , "content.aspx?cid=" + row["classid"]
                                          , row["classname"]
                                          );
            }
        }
        if ((re.ReadCookie("tempno") != null) && (re.ReadCookie("tempno") != "") || theBase.LoginUserMember != null)
        {
            string tempId;
            if (theBase.LoginUserMember != null)
            {
                tempId = theBase.LoginUserMember.MemberId;
            }
            else
            {
                tempId = re.ReadCookie("tempno");
            }
            DataTable table2 = SQLAccess.GreatDs("select DB_Car.carid,DB_Car.pronum,DB_Car.professionAreaName,DB_Car.price,DB_Car.sumprice,DB_Car.contents,DB_Shoppro.typeid,DB_Shoppro.proname,DB_Shoppro.proprice1,DB_Shoppro.propic2,DB_Shoppro.proid  from DB_Car inner join DB_Shoppro on DB_Car.productid=DB_Shoppro.proid where DB_Car.flag=0 and isnull(db_car.orderid,0) = 0 and DB_Car.temp='" + tempId + "'").Tables[0];

            if (theBase.LoginUserMember != null)
            {
                if (theBase.LoginUserMember.DicUserCardList != null && theBase.LoginUserMember.DicUserCardList.Count > 0)
                {
                    table2.DefaultView.RowFilter = " professionAreaName = ''";
                    this.shop = table2.DefaultView.Count.ToString();
                }
                else
                {
                    table2.DefaultView.RowFilter = " professionAreaName <> ''";
                    this.shop = table2.DefaultView.Count.ToString();
                }
            }
            else
            {
                this.shop = table2.Rows.Count.ToString();
            }
            
           
        }
        string str3 = "select classid,classname from DB_Productclass where parentid=0 and visible=1 order by classorder";
        DataTable table3 = SQLAccess.GreatDs(str3).Tables[0];
        if (table3.Rows.Count > 0)
        {
            foreach (DataRow row3 in table3.Rows)
            {
                string typemsg = this.typemsg;
                this.typemsg = typemsg + "<option value=" + row3["classid"].ToString() + ">" + row3["classname"].ToString() + "</option>";
            }
        }
        str3 = "select topicid,pic,picurl,visible from DB_topic where isnew=1 order by topicorder asc";
        table3 = SQLAccess.GreatDs(str3).Tables[0];
        if (table3.Rows.Count > 0 && table3.Rows[0]["visible"].ToString().ToLower() == "true")
        {
            this.sbTopic.Append("<a href='" + table3.Rows[0]["picurl"].ToString() + "?tid=" + table3.Rows[0]["topicid"].ToString() + "' target='_blank'><img width='1000px' border='0' height='55px' src='" + table3.Rows[0]["pic"].ToString() + "' border='0' /></a>");
        }
        else
        {
            this._displayTop = "display:none;";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {      
        this.Bind();
        this.BindCarInfo();
    }

    void BindCarInfo()
    {
        if (theBase.LoginUserMember != null)
        {
            _sbCarInfo.Append("<a class=\"car\" href=\"/cn/account.aspx\">去结算</a>");
        }
        else
        {
            _sbCarInfo.Append("<a class=\"thickbox car\" href=\"/cn/accountLogin.aspx?TB_iframe=true&height=370&width=640\">去结算</a>");
        }
    }


}

}